/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.omega_r.omegarecyclerview.ListAdapterExample;

import com.omega_r.libs.omegarecyclerview.base.BaseBean;
import com.omega_r.libs.omegarecyclerview.base.BaseViewHolder;
import com.omega_r.omegarecyclerview.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.Text;


public class ListAdapterViewHolder extends BaseViewHolder {
    private Text listAdapterItemTxt;
    private OnclickListener onclickListener;

    public void setOnclickListener(OnclickListener onclickListener) {
        this.onclickListener = onclickListener;
    }

    public ListAdapterViewHolder(Component itemView) {
        super(itemView);
        listAdapterItemTxt = (Text) findComponentById(ResourceTable.Id_list_adapter_item_txt);

    }


    @Override
    public void updateView(BaseBean baseBean) {
        super.updateView(baseBean);
        ListAdapterBean listAdapterBean = (ListAdapterBean) baseBean;
        listAdapterItemTxt.setText(listAdapterBean.getName());
        listAdapterItemTxt.setClickedListener(component -> {
            if (null != onclickListener) {
                onclickListener.clickListener(listAdapterBean.getName());
            }
        });
        listAdapterItemTxt.setLongClickedListener(component -> {
            if (null != onclickListener) {
                onclickListener.clickLongListener(listAdapterBean.getName());
            }
        });
    }

    public interface OnclickListener {
        void clickListener(String name);

        void clickLongListener(String name);
    }
}
